package wjx.database.bean;

import wjx.database.view.CodingFrm;

public class CodeThread extends Thread {
	private static String NAME = "加密-解密";
	public static String encodeS = null;// 代解密密文
	public static String decodeS = null;// 代加密原文
	public static String res = null;// 结果
	public static int STATE = 0;// 0-空闲 1-加密 2-解密

	
	public static void main(String[] args) {
		CodeThread thread = new CodeThread();
		thread.start();
	}

	@Override
	public void run() {
		CodingFrm coding = new CodingFrm();
		while (true) {
			System.out.println(res);
			if (StringUtil.isNotEmpty(decodeS)) {// 加密
				System.out.println("111");
				STATE = 1;
				coding.fresh();
				try {
					res = MyAESUtils.Encrypt(decodeS);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			} else if (StringUtil.isNotEmpty(encodeS)) {
				System.out.println("222");
				STATE = 2;
				coding.fresh();
				try {
					res = MyAESUtils.Decrypt(encodeS);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}	
			if (STATE != 0) {
				encodeS = "";
				decodeS = "";
				STATE = 0;			
			}
			try {
				synchronized(this){
					notify();
		        }
				sleep(2000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			coding.fresh();

		}
	}

	public void getEn(String s) {
		encodeS = s;
	}

	public void getDe(String s) {
		decodeS = s;
	}

}
